<h1>The Aspect Container</h1>

<p>
    In <b>Aspect PHP</b>, the aspect container is the class that contains all
    the aspect classes and pointcuts definitions. So let's build a new instance
    of that class:
</p>

<div class="code">
    <code>
        require_once dirname(__FILE__) . '/path/to/lib/aspectAutoloader.php';<br />
        aspectAutoloader::register();<br />
        <br />
        $aspectContainer = new aspectContainer();<br />
    </code>
</div>

<p class="notice">
    The first two lines calls the autoloader of the library. Once you've written
    these two lines, <b>Aspect PHP</b> is ready to be used without any further
    operations! Notice that we didn't add the opening <code>&lt;?php</code>.
    Don't forget to add it to your files.
</p>

<p>
    As <b>AOP</b> only has sense in an <b>OOP</b> environment, let's create two
    classes: <b>Foo</b> and <b>FooAspect</b>:
</p>

<div class="code">
    <code>
        <small>Foo.class.php</small><br />
        class Foo {<br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;public function doSomeStuff($fooParam) {<br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "I'm dealing with $fooParam!";<br />
        &nbsp;&nbsp;&nbsp;&nbsp;}<br />
        <br />
        }<br />
    </code>
</div>
<br />
<div class="code">
    <code>
        <small>FooAspect.class.php</small><br />
        class FooAspect {<br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;public function myBeforeAdvice() {<br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "I've been called before!\n";<br />
        &nbsp;&nbsp;&nbsp;&nbsp;}<br />
        <br />
        }<br />
    </code>
</div>

<p>
    Now let's make our aspect container do the work!
</p>

<div class="code">
    <code>
        require_once dirname(__FILE__) . '/path/to/lib/aspectAutoloader.php';<br />
        aspectAutoloader::register();<br />
        <br />
        require_once dirname(__FILE__) . '/Foo.class.php';<br />
        require_once dirname(__FILE__) . '/FooAspect.class.php';<br />
        <br />
        $aspectContainer = new aspectContainer();<br />
        $aspectContainer->doBefore('method(Foo->doSomeStuff())', 'FooAspect', 'myBeforeAdvice');<br />
        <br />
        $foo = new aspectProxy(new Foo());<br />
        $foo->doSomeStuff('AOP');<br />
    </code>
</div>

<p>
    Ok so what happened? We have called our aspect container and told him to
    cross-cut the method <i>doSomeStuff()</i> from the class <i>Foo</i> and
    executes the advice <i>myBeforeAdvice</i> from our aspect just before.
    Therefore, the <i>Foo</i> instance has been 'proxified' by the aspect proxy
    class to be able to intercept method calls.
    Let's take a look at the result:
</p>

<div class="code">
    <code>
        I've been called before!<br />
        I'm dealing with AOP!<br />
    </code>
</div>

<p class="notice">
    The different possibilities given by pointcut expressions, here:
    <code>'method(Foo->doSomeStuff())'</code> will be shown a little bit later.
</p>

<p>
    Ok! I don't know for you, but something I find really cool about <b>AOP</b>
    is the annotation system. This makes your <b>AOP</b> configuration very
    flexible and powerful. Although it is possible to fully use
    <b>Aspect PHP</b> with pure <b>PHP</b> code, let's now take a look at the
    aspect container builder.
</p>